package com.kaiyidiannao.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import com.kaiyidiannao.activity.foodpalace.DisplayActivity;

import java.util.List;

/**
 * Created by guanzhe on 14-4-23.
 */
public class CommonViewpagerAdapter extends PagerAdapter {
    private Context mContext;
    private List <View> mList;
    private ViewPager mViewPager;
    private List<String> mUrlList;

    public CommonViewpagerAdapter(Context context,List <View> list,ViewPager viewPager,List<String> urlList){
        mContext = context;
        mList = list;
        mViewPager = viewPager;
        mViewPager.setAdapter(this);
        mViewPager.setOnPageChangeListener(new MyPageChangeListener());
        mUrlList = urlList;
    }

    @Override
    public int getCount() {
        return mList == null ? 0 : mList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object o) {
        return view == o;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        container.addView(mList.get(position));
        return mList.get(position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(mList.get(position));
    }
    class MyPageChangeListener implements ViewPager.OnPageChangeListener{

        @Override
        public void onPageScrolled(int i, float v, int i2) {
            if(mViewPager != null){
                mViewPager.invalidate();
            }
        }

        @Override
        public void onPageSelected(int i) {

        }

        @Override
        public void onPageScrollStateChanged(int i) {

        }
    }
}
